package com.santu.edu.supporter.biz.order.helpbuy.controller;

import com.santu.edu.supporter.biz.order.helpbuy.pojo.dto.HelpBuyOrderDTO;
import com.santu.edu.supporter.biz.order.helpbuy.pojo.params.HbOrderAddParam;
import com.santu.edu.supporter.biz.order.helpbuy.pojo.params.HbOrderUpdateParam;
import com.santu.edu.supporter.biz.order.helpbuy.service.HelpBuyService;
import com.santu.edu.supporter.util.PageData;
import lombok.RequiredArgsConstructor;
import org.apache.ibatis.annotations.Param;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;

/**
 * @author luoyaoqi
 * @createTime 2024/2/21
 * @description
 */
@RestController
@Validated
@RequiredArgsConstructor
@RequestMapping("help/buy")
public class HelpBuyController {

    private final HelpBuyService helpBuyService;

    @PostMapping("add")
    public Boolean addOrder(@RequestBody @Valid HbOrderAddParam addParam) {
        return helpBuyService.addOrder(addParam);
    }

    @PostMapping("update")
    public Boolean updateOrder(@RequestBody @Valid HbOrderUpdateParam updateParam) {
        return helpBuyService.updateOrder(updateParam);
    }

    @PostMapping("cancel")
    public Boolean cancelOrder(@Param("orderId不能为空") String orderId) {
        return helpBuyService.cancelOrder(orderId);
    }

    @GetMapping("get/by/orderCode")
    public PageData<HelpBuyOrderDTO> getBuildingsList(@NotBlank(message = "schoolId不能为空")
                                                      String schoolId,
                                                      String userId,
                                                      Integer orderType,
                                                      int page,
                                                      int size) {
        return helpBuyService.getOrderList(schoolId, userId, orderType, page, size);
    }
}
